package com.ruoyi.bus.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.bus.service.NoGenerateServlce;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bus.domain.NetworkInfo;
import com.ruoyi.bus.service.INetworkInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网点信息Controller
 *
 * @author ruoyi
 * @date 2020-04-09
 */
@Controller
@RequestMapping("/bus/networkInfo")
public class NetworkInfoController extends BaseController {
    private String prefix = "bus/networkInfo";

    @Autowired
    private NoGenerateServlce noGenerateServlce;

    @Autowired
    private INetworkInfoService networkInfoService;

    @RequiresPermissions("bus:networkInfo:view")
    @GetMapping()
    public String networkInfo() {
        return prefix + "/networkInfo";
    }

            /**
         * 查询网点信息列表
         */
        @RequiresPermissions("bus:networkInfo:list")
        @PostMapping("/list")
        @ResponseBody
        public TableDataInfo list(NetworkInfo networkInfo) {
            startPage();
            return getDataTable(networkInfoService.list(new QueryWrapper<>(networkInfo)));
        }
    
    /**
     * 导出网点信息列表
     */
    @RequiresPermissions("bus:networkInfo:export")
    @Log(title = "网点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NetworkInfo networkInfo) {
        List<NetworkInfo> list = networkInfoService.list(new QueryWrapper<>(networkInfo));
        ExcelUtil<NetworkInfo> util = new ExcelUtil<>(NetworkInfo.class);
        return util.exportExcel(list, "networkInfo");
    }

            /**
         * 新增网点信息
         */
        @GetMapping("/add")
        public String add(ModelMap mmap) {
            NetworkInfo networkInfo = new NetworkInfo();
            networkInfo.setNetworkId(noGenerateServlce.getSeqNo("NT",5));
            mmap.put("networkInfo", networkInfo);
            return prefix + "/edit";
        }
    
    /**
     * 新增保存网点信息
     */
    @RequiresPermissions("bus:networkInfo:add")
    @Log(title = "网点信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NetworkInfo networkInfo) {
        return toAjax(networkInfoService.save(networkInfo));
    }

    /**
     * 修改网点信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        NetworkInfo networkInfo = networkInfoService.getById(id);
        mmap.put("networkInfo", networkInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存网点信息
     */
    @RequiresPermissions("bus:networkInfo:edit")
    @Log(title = "网点信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NetworkInfo networkInfo) {
        return toAjax(networkInfoService.updateById(networkInfo));
    }

            /**
         * 删除网点信息
         */
        @RequiresPermissions("bus:networkInfo:remove")
        @Log(title = "网点信息", businessType = BusinessType.DELETE)
        @PostMapping( "/remove")
        @ResponseBody
        public AjaxResult remove(String ids) {
            return toAjax(networkInfoService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
        }
        }
